<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>游戏大厅</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
<script src="https://cdn.bootcss.com/dayjs/1.7.8/dayjs.min.js"></script>
<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="/css/common/common.css" rel="stylesheet" type="text/css">
<style type="text/css">
.hot-game {
	height: 4.5rem;
	background-color: #fff;;
	margin-bottom: 1rem;
	display: flex;
	padding-left: 0.2rem;
	padding-right: 0.2rem;
}

.hot-game-logo {
	flex: 1.2;
	display: flex;
	align-items: center;
	justify-content: center;
}

.hot-game-logo img {
	border-radius: 4rem;
	height: 4rem;
}

.hot-game-body {
	flex: 4;
	display: flex;
	flex-direction: column;
	margin-top: 0.5rem;
}

.lottery-closed-body-item, .lotterying-body-item {
	color: orange;
}

.current-issue-body-item {
	color: #838793;
}

.lottery-num {
	
}

.lottery-num span {
	width: 1.54688rem;
	height: 1.54688rem;
	margin-right: .29375rem;
	float: left;
	background: #d22018;
	font-size: 1rem;
	color: #fff;
	text-align: center;
	line-height: 1.54688rem;
	border-radius: 100%;
}

.lottery-angle-right {
	float: right;
	padding-right: 1.5rem;
}

.lottery-angle-right i {
	font-size: 1.8rem;
	color: #838793;
}

.lately-lottery-result {
	height: 4.5rem;
	background-color: #fff;;
	margin-bottom: 1rem;
	display: flex;
	padding-left: 0.2rem;
	padding-right: 0.2rem;
}

.lately-lottery-result-body {
	flex: 4;
	display: flex;
	flex-direction: column;
	margin-top: 0.5rem;
	padding-left: 1.2rem;
}

.betting-btn, .lottery-trend-btn {
	width: 50%;
	height: 100%;
	border: 0;
	padding: 0;
}

.betting-btn {
	color: #d22018;
	background: #f2f2f2;
}

.lottery-trend-btn {
	color: #fff;
	background: #d22018;
}
</style>
</head>

<body>
	<div th:replace="common/header::html"></div>
	<div id="lotteryHall" v-cloak>
		<nav class="navbar fixed-top bg-danger header-navbar" v-show="showLatelyLotteryResultFlag">
			<i class="fa fa-angle-left" aria-hidden="true" style="float: left; font-size: 1.8rem;" v-on:click="showGameSituation"></i><a class="navbar-brand">{{gameName}}</a>
		</nav>
		<div class="page-body" style="background: #f2f2f2;">
			<div v-show="!showLatelyLotteryResultFlag">
				<div class="hot-game" v-for="gameSituation in gameSituations" v-on:click="showLatelyLotteryResult(gameSituation)">
					<div class="hot-game-logo">
						<img v-bind:src="'/images/lottery-logo/' + gameSituation.gameCode.toLowerCase() + '.png'" />
					</div>
					<div class="hot-game-body">
						<div class="hot-game-body-item">
							<span>{{gameSituation.gameName}}</span> <span style="float: right; font-size: 0.9rem; padding-right: 0.6rem; color: #838793;"> <label style="padding-right: 1rem;">第{{gameSituation.currentIssue != null ? gameSituation.currentIssue : gameSituation.nextIssue}}期</label> <label class="">{{gameSituation.countdownClock}}</label>
							</span>
						</div>
						<div class="hot-game-body-item lottery-num-body-item" v-show="gameSituation.currentIssue != null">
							<div class="hot-game-body-item lotterying-body-item" v-show="gameSituation.preIssueLotteryNum == null">
								<span>正在开奖...</span><label class="lottery-angle-right"><i class="fa fa-angle-right" aria-hidden="true"></i></label>
							</div>
							<div class="lottery-num" v-show="gameSituation.preIssueLotteryNum != null">
								<span v-for="num in splitlotteryNum(gameSituation.preIssueLotteryNum)">{{num}}</span> <label class="lottery-angle-right"><i class="fa fa-angle-right" aria-hidden="true"></i></label>
							</div>
						</div>
						<div class="hot-game-body-item lottery-closed-body-item" v-show="gameSituation.currentIssue == null">
							<span>休市中...</span> <label class="lottery-angle-right"><i class="fa fa-angle-right" aria-hidden="true"></i></label>
						</div>
					</div>
				</div>
			</div>
			<div v-show="showLatelyLotteryResultFlag">
				<div class="hot-game lately-lottery-result" v-for="lotteryResult in lotteryResults">
					<div class="lately-lottery-result-body">
						<div>
							<span style="font-size: 0.9rem; padding-right: 0.6rem; color: #838793;"> 第{{lotteryResult.issueNum}}期 </span> <span>{{lotteryResult.endTime}}</span>
						</div>
						<div>
							<div class="lotterying-body-item" v-show="lotteryResult.lotteryNum == null">正在开奖...</div>
							<div class="lottery-num" v-show="lotteryResult.lotteryNum != null">
								<span v-for="num in splitlotteryNum(lotteryResult.lotteryNum)">{{num}}</span>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<nav class="navbar fixed-bottom bg-light footer-navbar" style="padding: 0;" v-show="showLatelyLotteryResultFlag">
			<button type="button" class="btn btn-link betting-btn">立即投注</button>
			<button type="button" class="btn btn-link lottery-trend-btn">走势图</button>
		</nav>
	</div>
	<div th:replace="common/footer::html"></div>
	<script type="text/javascript">
		var lotteryHallVM = new Vue({
			el : '#lotteryHall',
			data : {
				gameSituations : [],
				gameName : '',
				lotteryResults : [],
				showLatelyLotteryResultFlag : false
			},
			computed : {},
			created : function() {
			},
			mounted : function() {
				headerVM.title = '开奖信息';
				this.loadAllGameSituation();
			},
			methods : {
				loadAllGameSituation : function() {
					var that = this;
					that.$http.get('/game/findAllGameSituation').then(function(res) {
						var result = res.body.data;
						for (var i = 0; i < result.length; i++) {
							var endTime = result[i].currentIssueEndTime;
							if (endTime == null) {
								endTime = result[i].nextIssueEndTime;
							}
							var second = dayjs(endTime).diff(dayjs(res.body.timestamp), 'second');
							result[i].second = second;
							result[i].countdownClock = '';
						}
						that.gameSituations = result;
						that.countdown();
					});
				},

				countdown : function() {
					var that = this;
					var countdownInterval = window.setInterval(function() {
						var gameSituations = that.gameSituations;
						var clearIntervalFlag = true;
						for (var i = 0; i < gameSituations.length; i++) {
							var second = gameSituations[i].second;
							if (second < 0) {
								continue;
							}
							gameSituations[i].countdownClock = that.buildCountdownClock(second);
							second--;
							gameSituations[i].second = second;
							clearIntervalFlag = clearIntervalFlag && (second < 0);
						}
						if (clearIntervalFlag) {
							console.log(gameSituations);
							window.clearInterval(countdownInterval);
						}
					}, 1000);
				},

				buildCountdownClock : function(second) {
					var that = this;
					var countdownHour = 0;
					var countdownMinute = 0;
					var countdownSecond = 0;
					if (second > 0) {
						countdownHour = parseInt(second / (60 * 60) % 24);
						countdownMinute = parseInt(second / 60 % 60);
						countdownSecond = parseInt(second % 60);
					}
					if (countdownHour < 10) {
						countdownHour = '0' + countdownHour;
					}
					if (countdownMinute < 10) {
						countdownMinute = '0' + countdownMinute;
					}
					if (countdownSecond < 10) {
						countdownSecond = '0' + countdownSecond;
					}
					return countdownHour + ':' + countdownMinute + ':' + countdownSecond;
				},

				splitlotteryNum : function(lotteryNum) {
					if (lotteryNum == null || lotteryNum == '') {
						return [];
					}
					return lotteryNum.split(',');
				},

				showLatelyLotteryResult : function(gameSituation) {
					var that = this;
					that.$http.get('/issue/findLatelyThe50TimeIssue', {
						params : {
							gameCode : gameSituation.gameCode
						}
					}).then(function(res) {
						that.lotteryResults = res.body.data;
						that.showLatelyLotteryResultFlag = true;
						that.gameName = gameSituation.gameName;
						headerVM.showHeaderFlag = false;
						footerVM.showFooterFlag = false;
					});
				},

				showGameSituation : function() {
					this.showLatelyLotteryResultFlag = false;
					headerVM.showHeaderFlag = true;
					footerVM.showFooterFlag = true;
				}

			}
		});
	</script>
</body>
</html>